clear all
set more off
* set directory 

********************************************************************************
* TABLE 2 -- MAIN DD ESTIMATES


********************************************************************************
* PANEL A--BASELINE TWFE

use analysis_file,clear

* sample restrictions
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'

* single family
reghdfe pc_single after_treatment  ///
	,absorb(id state_year) vce(cl statefips)
gen in_sample=e(sample)

* multi

reghdfe pc_lessSingle after_treatment  ///
	,absorb(id state_year) vce(cl statefips)

* all
	
reghdfe pc_all after_treatment if in_sample==1 ///
	,absorb(id state_year) vce(cl statefips)
	
* lihtc	

reghdfe li_ind after_treatment if year<2016 & year>1986  ///
	,absorb(id state_year) vce(cl statefips)


	
********************************************************************************
* PANEL B--MATCHED SAMPLE WITH CS ESTIMATOR


use matched_analysis_file, clear

* sample restrictions
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'

* get treatment year into the form required by csdid command
replace treatment_year=0 if treatment_year==.
replace treatment_year=treatment_year+1 if treatment_year !=0

* compute average effect for each outcome variable
csdid pc_all statefips pop80 pct_white80 pct_owned80 median_hh_income80 ///
	, ivar(id) time(year) gvar(treatment_year) cluster(statefips)
estat simple

csdid pc_single statefips pop80 pct_white80 pct_owned80 median_hh_income80 ///
	, ivar(id) time(year) gvar(treatment_year) cluster(statefips)
estat simple

csdid pc_lessSingle statefips pop80 pct_white80 pct_owned80 median_hh_income80 ///
	, ivar(id) time(year) gvar(treatment_year) cluster(statefips)
estat simple

csdid li_ind statefips pop80 pct_white80 pct_owned80 median_hh_income80 ///
	, ivar(id) time(year) gvar(treatment_year) cluster(statefips)
estat simple

********************************************************************************
* TABLE 2 PANEL C--MATCHED SAMPLE WITH TWFE

use matched_analysis_file, clear

* sample restrictions
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'

* single family
reghdfe pc_single after_treatment ///
	,absorb(id state_year) vce(cl statefips)
gen in_sample=e(sample)

* multi family	
reghdfe pc_lessSingle after_treatment   ///
	,absorb(id state_year) vce(cl statefips)

* all	
reghdfe pc_all after_treatment if in_sample==1  ///
	,absorb(id state_year) vce(cl statefips)
	
* lihtc
reghdfe li_ind after_treatment if year<2016 & year>1986  ///
	,absorb(id state_year) vce(cl statefips)

